﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using PRET.ReportControlLib.ServiceReference;
using PRET.ReportDataDefine.UIData;

namespace PRET.ReportControlLib.ReportView
{
    public partial class TeamAttendanceReportView : UserControl
    {
        private PRETWebServiceClient adapter = null;

        public TeamAttendanceReportView()
        {
            InitializeComponent();
            adapter = new PRETWebServiceClient();
            this.teamAttendanceFilter.showReportEvent += teamAttendanceFilter_showReportEvent;
        }

        void teamAttendanceFilter_showReportEvent(object sender, Controls.ShowTeamAttendanceReportViewEventArgs args)
        {
            try
            {
                this.teamAttendanceFilter.EnableControls(false);

                if (this.adapter == null)
                {
                    MessageBox.Show("TeamAttendanceReportView 没有初始化Server Adapter!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                this.teamAttReportViewer.LocalReport.DataSources.Clear(); //clear report
                TeamAttendanceMain teams = this.adapter.GetAllTeamAttendance(args.Month);
                if (teams.TeamList != null && teams.TeamList.Count > 0)
                {
                    Microsoft.Reporting.WinForms.ReportDataSource teamDataset = new Microsoft.Reporting.WinForms.ReportDataSource("TeamAttendanceDS"); // set the datasource
                    this.teamAttReportViewer.LocalReport.DataSources.Add(teamDataset);
                    teamDataset.Value = teams.TeamList;

                    Microsoft.Reporting.WinForms.ReportDataSource restDataset = new Microsoft.Reporting.WinForms.ReportDataSource("TeamAttendanceRestHoursDS"); // set the datasource
                    this.teamAttReportViewer.LocalReport.DataSources.Add(restDataset);
                    restDataset.Value = new List<TeamAttendanceRestHours> { teams.TeamHour };
                    //this.teamAttendanceMonth.SetAHours = teams.TeamHour.ATeamHours;
                    //this.teamAttendanceMonth.SetBHours = teams.TeamHour.BTeamHours;
                    //this.teamAttendanceMonth.SetCHours = teams.TeamHour.CTeamHours;
                    //this.teamAttendanceMonth.SetDHours = teams.TeamHour.DTeamHours;
                    //this.teamAttendanceMonth.SetEHours = teams.TeamHour.ETeamHours;
                    //this.teamAttendanceMonth.SetFHours = teams.TeamHour.FTeamHours;
                }
                this.teamAttReportViewer.LocalReport.Refresh();
                this.teamAttReportViewer.RefreshReport();
            }
            catch (Exception ex)
            {
                string msg = string.Format("TeamAttendanceReportView.teamAttendanceFilter_showReportEvent() Failed: {0}.\r\nDetail: {1}", ex.Message, ex.StackTrace);
                MessageBox.Show(msg, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            { 
                this.teamAttendanceFilter.EnableControls(true);
            }

        }
    }
}
